// 新增单一项目阳性率统计页面  20211012 耿琰
import React from 'react'
// ===================================================================== Temp
import SearchForm from '#cpt/temp/SearchForm'
import Table from '#cpt/temp/Table'
import TableControls from '#cpt/temp/TableControls'
import Controls from '#cpt/temp/Controls'
// ===================================================================== global declare
const { $fn, $Lazy } = window
// ===================================================================== Lazy
const Page 					= $Lazy.load(()=>import('#tp/page/page-container'))
const $cache 				= $Lazy.file(()=>import('#private/cache-api'))
const ControlModal 			= $Lazy.state(()=>import('./cpt/control-modal'))
const $time 				= $Lazy.file(()=>import('@com/utils/time'))
// ===================================================================== component
class Index extends React.Component{
	state = {
		data:[],
		pag: {},
		// 搜索表单列表
		forms : [
			{ label: '统计时间',		names: ['start_at','end_at'], 	name:'jz-time',	type: 'date-range' },
			{ label: '科室',		name: 'project_parent_id',		type: 'select', loading:true, idStr:'uuid' },
			{ label: '岗位',		name: 'project_id',				type: 'select', loading:true },
			{ label: '自然项目',		name: 'parent_kind_id',			type: 'select', loading:true },
			/* 增加结果类型筛选条件 2021-08-24  --耿琰 */
			// { label: '结果类型',		name: 'positive',				type: 'select', loading:true, idStr:'id' },
		]
	}
	
	model = {}
	
	componentDidMount(){
		this.getSelect()
		// 设置时间默认值
		$time.then(f=>{
			const arr = f.duration['30']()
			this.resetModel = { start_at: arr[0], end_at: arr[1], 'jz-time':arr }
			this.model = $fn.copy(this.resetModel)
			if(window.isInit){
				this.fetch()
			}
		})
	}
	//获取下拉数据
	getSelect = () => {
		const { forms } = this.state
		
		$cache.then( async f => {
			// 科室
			$fn.setRow(forms, 'project_parent_id', await f.getCache({ api:'ke_shi' } ) )
			// 岗位
			$fn.setRow(forms, 'project_id', await f.getCache({ api:'gang_wei' } ) )
			// 自然项目
			$fn.setRow(forms, 'parent_kind_id', await f.getCache({ api:'nature_project' } ) )
			// 结果类型
			// $fn.setRow(forms, 'positive', await f.getCache({ api:'result_type', param:{ type:1 } } ) )
			this.setState({ forms })
		})
	}
	
	// paging
	fetch = () => $fn.fetch.call(this,'statistics/labPositiveRateCount',{isIndex:true,param:{is_parent_kind:1},
		callback: result => this.setState({ result })
	})
	
	// 表单
	// 新增送检单位 20211102 耿琰
	cols = [
		{ title: '送检单位', 	dataIndex: 'hosp_name', 				width:100 },
		{ title: '科室', 		dataIndex: 'project_parent_name', 		width:100 },
		{ title: '岗位', 		dataIndex: 'project_name', 				width:100 },
		{ title: '项目', 		dataIndex: 'single_kind_name', 			width:150 },
		{ title: '阳性样本', 	dataIndex: 'count_positive', 			...$fn.table.num },
		{ title: '样本总数', 	dataIndex: 'count_total', 				...$fn.table.num },
		{ title: '阳性率', 		dataIndex: 'positive_rate', 			...$fn.table.num },
		TableControls.controls.call(this)
	]
	// 表格操作按钮
	table_controls = (text, rows) => {
		return [
			TableControls.click.call(this, '项目明细', ()=> this.modal.open({...this.model, ...rows}) )
		]
	}
	// 操作按钮
	controls = () => {
		return [
			Controls.exports.call(this, 'statistics/labPositiveRateCount', {param:{is_parent_kind:1}}),			// 导出
		]
	}
	
	render(){
		const { result } = this.state
		return (
			<>
				<Page title='自然项目阳性率统计' controls={this.controls()}>
					{/* 搜索 */}
					{ SearchForm.call(this,{timeStr:'30'}) }
					{/* 表格 */}
					{ Table.call(this,
						{ isInit:window.isInit,
							isIndex:true,
							suffix: (
							<>
								<div className='ml10 g9'>当前页样本总数 <b className='f14 c0'>{result?.current_page_total}</b></div>
								<div className='ml10 g9'>当前页阳性样本总数 <b className='f14 c0'>{result?.current_page_positive_total}</b></div>
							</>
						)
						}) 
					}
				</Page>
				{/* 项目明细弹窗 */}
				<ControlModal onRef={ref=>this.modal=ref} />
			</>
		)
	}
}

export default Index